package com.qf.service.impl;

import com.qf.entity.UserRole;
import com.qf.entity.BackendUser;
import com.qf.mapper.BackendUserMapper;
import com.qf.service.BackendUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

@Slf4j
@Service
public class BackendUserServiceImpl implements BackendUserService {

    @Resource
    private BackendUserMapper backendUserMapper;

    @Override
    public BackendUser findByUsername(String username) {
        BackendUser backendUser = new BackendUser();
        backendUser.setBackendCode(username);

        return backendUserMapper.selectOne(backendUser);
    }

    @Override
    public Set<UserRole> findRolesById(Long id) {
        return backendUserMapper.findRolesById(id);
    }

    @Override
    public Set<String> findPermissionsByRoleIds(Set<Integer> roleIds) {

        Map<String,Object> map = new HashMap<>();
        map.put("roleIds",roleIds);

        return backendUserMapper.findPermissionsByRoleIds(map);
    }
}
